import { defineStore } from 'pinia';
import { ref } from 'vue';

export const useTokenStore = defineStore('token', () => {
  // 状态
  const token = ref<string>('');

  // 设置token
  const setToken = (newToken: string): void => {
    token.value = newToken;
  };

  // 清除token
  const clearToken = (): void => {
    token.value = '';
  };

  return {
    token,
    setToken,
    clearToken
  };
}, {
  persist: {
    key: 'cloud-library-token',
    storage: localStorage
  }
});
